function parseText(txt) {
	var rows = txt.split("\n");
	var logs = Array();
	for (i in rows) {
		var logEntry = parseRow(rows[i].trim());
		var log = fx(logs, logEntry.playerName, function() { return new Log(logEntry.playerName); });
		log.entries.push(logEntry);
	}
	return logs;
}

function fx(a, k, f) {
	if (a[k] == undefined) {
		a[k] = f(k);
	}
	return a[k];
}

function parseRow(txt) {

/*
1: "13:06:26:23:13:54.4"
2: ""
3: "Efsane"
4: "200068387@6126113 Efsane@sarhand"
5: ""
6: "*"
7: "Target Dummy"
8: "C[214575 Entity_Targetdummy]"
9: "Plague Fire Weapon"
10: "Pn.5haibx"
11: "Fire"
12: ""
13: "9.37662"
14: "8.59609"
*/

	var match = txt.match(/^(.*):(.*?):(.*?),P\[(.*?)\],(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*)$/);

	if (match != null)
	{
		var time = parseTime(match[1]);
		var playerName = match[3];
		var hireling = match[5];
		var target = match[7];
		var spell = match[9];
		var damageType = match[11];
		var hitType = match[12];
		var value = Number(match[13]);
		var value2 = Number(match[14]);
	}

	return new Entry(txt,
		time,
		playerName,
		hireling,
		target,
		spell,
		damageType,
		value,
		value2);

}

function parseTime(str) {
	var match = str.match(/(\d\d):(\d\d):(\d\d):(\d\d):(\d\d):(\d\d)\.(\d)/);
	if (match != null) {
		return new Date(2000 + Number(match[1]), Number(match[2]) - 1, match[3], match[4], match[5], match[6] , 100 * Number(match[7]));
	}
	else
		return null;
}

function Entry(txt, time, playerName, hireling, target, spell, damageType, hitType, value, value2) {
	this.txt = txt;
	this.time = time;
	this.playerName = playerName;
	this.hireling = hireling;
	this.target = target;
	this.spell = spell;
	this.damageType = damageType;
	this.hitType = hitType;
	this.value = value;
	this.value2 = value2;

	this.toString = function() {
		return this.playerName + ", " + this.spell + ", " + this.value;
	}
}

function Log(playerName) {
	this.entries = Array();
	this.playerName = playerName;
}

